// Tierless
// Copyright © 2010 Alphora
// This file is licensed under a modified BSD-license (see tierless_license.txt).
using System.Collections.Generic;
using System.Text;

namespace Tierless.Framework.Utilities
{
	/// <summary>
	/// Provides extension methods for dealing with string arrays in the Tierless framework.
	/// </summary>
	public static class StringArrayExtensions
	{
		/// <summary>
		/// Combines the given strings into one string, separating each with the given delimiter.
		/// </summary>
		/// <param name="values">The strings to be combined.</param>
		/// <param name="delimiter">The delimiter to be used.</param>
		/// <returns>A string containing the combined values of all the given strings, separated by the delimiter.</returns>
		public static string Combine(this IEnumerable<string> values, string delimiter)
		{
			var result = new StringBuilder();
			foreach (var stringValue in values)
			{
				if (result.Length > 0)
					result.Append(delimiter);
				result.Append(stringValue);
			}
			return result.ToString();
		}

		/// <summary>
		/// Combines the given strings using an empty delimiter.
		/// </summary>
		/// <param name="values">The strings to be combined.</param>
		/// <returns>A string containing the concatenation of all the given strings.</returns>
		public static string Combine(this IEnumerable<string> values)
		{
			return Combine(values, "");
		}
	}
}